﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MiniSched.Orm.Enumerations;

namespace MiniSched.Orm.Initialization {

    internal class ChurchTemplateCreator : TemplateCreator {

        public override void Create(string organizationName, MiniSchedContext context) {
            if (null == context) throw new ArgumentNullException("context");



            var jobs = new[] { "Usher", "Sacristan", "Alter Server", "Music Leader", "Eucharistic Minister" }
                .Select(jobName => context.GetOrCreate<Job>(j => j.JobName == jobName, () => new Job { JobName = jobName }))
                .ToDictionary(job => job.JobName);

            var mass = context.GetOrCreate<Event>(e => e.EventName == "Mass", () => new Event { EventName = "Mass" });

            var organization = new Organization { OrganizationName = organizationName };

            var massTimes = new[] {
                new {
                    RecurrenceTime = TimeSpan.Parse("11:00:00"),
                    RecurrenceType = RecurrenceTypeOption.EveryDay,
                    JobCount = new Dictionary<string, int> {
                        { "Usher", 3 },
                        { "Sacristan", 1 },
                        { "Alter Server", 3 },
                        { "Music Leader", 1 },
                        { "Eucharistic Minister", 7 }
                    }
                }
            };

            foreach (var massTime in massTimes) {
                var massEvent = new OrganizationEvent {
                    Event = mass,
                    Organization = organization,
                    RecurrenceTime = massTime.RecurrenceTime,
                    RecurrenceType = context.RecurrenceTypes.GetOrCreate(massTime.RecurrenceType)
                };

                var massEventJobs = massEvent.EventJobs ?? new List<EventJob>();
            }

            throw new NotImplementedException();
        }
    }
}
